"""
@File    :   models.py
@Time    :   2024/02/19 09:22:10
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   社交登录客户端数据模型
"""

from datetime import datetime

from sqlalchemy import (
    JSON,
    BigInteger,
    Boolean,
    Column,
    DateTime,
    Index,
    Integer,
    String,
    UniqueConstraint,
)

from src.models.models import OrmBase


class SocialClient(OrmBase):
    """社交登录客户端数据模型"""

    __tablename__ = "system_social_client"
    __table_args__ = (
        UniqueConstraint("name", "tenant_id"),
        UniqueConstraint("client_id", "tenant_id"),
        Index(None, "client_id", "tenant_id"),
    )

    id = Column(BigInteger(), primary_key=True, autoincrement=True, comment="主键")
    status = Column(
        Boolean(), default=True, nullable=False, comment="状态"
    )  # (True正常 False停用)
    remark = Column(String(300), default="", nullable=False, comment="备注")
    show_order = Column(
        Integer(), nullable=False, index=True, default=1, comment="显示顺序"
    )
    create_datetime = Column(
        DateTime(), nullable=False, default=datetime.now, index=True, comment="创建时间"
    )
    update_datetime = Column(
        DateTime(),
        nullable=False,
        default=datetime.now,
        onupdate=datetime.now,
        index=True,
        comment="修改时间",
    )
    # 创建者用户名(级联删除)
    creator_username = Column(
        String(20), default="", nullable=False, comment="创建者用户名"
    )
    # 修改者用户名(级联删除)
    updater_username = Column(
        String(20), default="", nullable=False, comment="修改者用户名"
    )
    # 租户ID(级联删除)
    tenant_id = Column(BigInteger(), nullable=False, index=True, comment="租户ID")
    name = Column(String(100), nullable=False, comment="应用名")
    social_type = Column(
        String(100), nullable=False, index=True, comment="社交平台类型"
    )
    client_id = Column(String(255), nullable=False, comment="客户端编号")
    client_secret = Column(String(255), nullable=False, comment="客户端密钥")
    additional_info = Column(
        JSON(), nullable=False, default={}, comment="附加信息(Json格式)"
    )
